/*Copyright ©2015 TommyLemon(https://github.com/TommyLemon)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/

package com.mego.maq.view;

import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

import com.mego.maq.R;
import com.mego.maq.database.dbmodel.Commandlog;
import com.mego.maq.database.manager.CommandlogCenter;

import java.util.ArrayList;

import zuo.biao.library.base.BaseView;
import zuo.biao.library.model.Entry;
import zuo.biao.library.util.StringUtil;


public class DemoView extends BaseView<Entry<Integer, String>> implements OnClickListener {
    private static final String TAG = "DemoView";

    public DemoView(Activity context, ViewGroup parent) {
        super(context, R.layout.commandlog_view, parent);  //TODO demo_view改为你所需要的layout文件
    }


    //示例代码<<<<<<<<<<<<<<<<
    public TextView tv_commandc;
    public TextView tv_commandt;
    public TextView tv_time;

    //示例代码>>>>>>>>>>>>>>>>
    @Override
    public View createView() {

        //示例代码<<<<<<<<<<<<<<<<
        tv_commandc = findView(R.id.tv_commandc, this);
        tv_commandt = findView(R.id.tv_commandt);
        tv_time = findView(R.id.tv_time);
        //示例代码>>>>>>>>>>>>>>>>

        return super.createView();
    }


    @Override
    public void bindView(Entry<Integer, String> data_) {
        //示例代码<<<<<<<<<<<<<<<<
        super.bindView(data_ != null ? data_ : new Entry<Integer, String>());
        
        itemView.setBackgroundResource(selected ? R.drawable.alpha3 : R.drawable.white_to_alpha);

        int index = data.getKey();
        ArrayList<Commandlog> commandlogList = CommandlogCenter.getInstance().getCommandlogList();
        if (index < commandlogList.size()) {
            Commandlog clog = commandlogList.get(index);
            tv_commandt.setText(StringUtil.getTrimedString(clog.getTitle()));
            tv_commandc.setText(StringUtil.getTrimedString(clog.getContent()));
            tv_time.setText(StringUtil.getTrimedString(clog.getLogtimeStr()));
        }

        //示例代码>>>>>>>>>>>>>>>>
    }


    //示例代码<<<<<<<<<<<<<<<<
    @Override
    public void onClick(View v) {
        if (data == null) {
            return;
        }
        switch (v.getId()) {
            case R.id.tv_commandc:
//			data.setKey("New " + data.getKey());
//			bindView(data);
//			if (onDataChangedListener != null) {
//				onDataChangedListener.onDataChanged();
//			}
                break;
            default:
                break;
        }
    }
    //示例代码>>>>>>>>>>>>>>>>


}
